﻿using MyCommunity.Models;
using MyCommunity.DataAccess;
using System.Collections.Generic;
using MyCommunity.BusinessLogic;
using System;

class EventService : IEventService
{
    private readonly IEventDAL dal;

    public EventService(IEventDAL dal)
    {
        this.dal = dal;
    }

    public List<Event> GetAllEvents(String searchString)
    {
        if (!String.IsNullOrEmpty(searchString))
        {
            return this.dal.FindEvents(searchString);
        }

        return this.dal.GetAllEvents();
    }

    public Event GetEvent(int eventId)
    {
        return this.dal.GetEvent(eventId);
    }

    public void CreateEvent(EventRegisterModel eventRegisterModel)
    {
        Event newEvent = new Event();
        eventRegisterModel.ApplyChanges(newEvent);
        this.dal.Add(newEvent);
    }

    public void DeleteEvent(Event eventDel)
    {
        this.dal.Remove(eventDel);
    }
 

    public void SaveChanges()
    {
        this.dal.Save();
    }
}